/*
package com.hong.utils.executors;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

*/
/**
 * @Auther: Administrator
 * @Date: 2018/7/30 21:25
 * @Description:
 *//*

public class CompletableFutureExample2 {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
//        supplyAsync();
//        Thread.currentThread().join();
//        Future<?> future = runAsync();
//        future.get();
//        Thread.currentThread().join();

        */
/*Future<Void> futurel = completed("Hello");
        System.out.println(futurel.isDone());
        Thread.currentThread().join();*//*


        System.out.println(">>>>>>>>>"+anyOf().get());
    }

    private static Future<Void> completed(String data) {
        return CompletableFuture.completedFuture(data).thenAccept(System.out::println);
    }


    private static Future<?> anyOf(){
        return CompletableFuture.runAsync(() -> {
            try {
                System.out.println("obj=====Start");
                TimeUnit.SECONDS.sleep(5);
                System.out.println("obj=====end");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).whenComplete((v, t) -> System.out.println("=======over========")),
        CompletableFuture.supplyAsync(() -> {
            try {
                System.out.println("2=====Start");
                TimeUnit.SECONDS.sleep(5);
                System.out.println("2=====end");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "hello";
        }).whenComplete((v, t) -> System.out.println(v+ "=======over========"));
    }

    */
/**
     *结束之后运行
     *//*

    private static Future<?> runAsync(){
        CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
            try {
                System.out.println("obj=====Start");
                TimeUnit.SECONDS.sleep(5);
                System.out.println("obj=====end");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).whenComplete((v, t) -> System.out.println("=======over========"));
        return  future;
    }

    private static void supplyAsync() {
        CompletableFuture.supplyAsync(Object::new)
                .thenAcceptAsync(obj->{

                    try {
                        System.out.println("obj=====Start");
                        TimeUnit.SECONDS.sleep(5);
                        System.out.println("obj====="+ obj);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }).runAfterBoth(CompletableFuture.supplyAsync(()->"Hello")
                .thenAcceptAsync(s->{

                    try {
                        System.out.println("String====Start");
                        TimeUnit.SECONDS.sleep(3);
                        System.out.println("String======"+s);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }),()-> System.out.println("=======finished===========")
        );
    }


}
*/
